package com.baitai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baitai.common.core.domain.model.LoginUser;
import com.baitai.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baitai.common.annotation.Log;
import com.baitai.common.core.controller.BaseController;
import com.baitai.common.core.domain.AjaxResult;
import com.baitai.common.enums.BusinessType;
import com.baitai.system.domain.UserOpinion;
import com.baitai.system.service.IUserOpinionService;
import com.baitai.common.utils.poi.ExcelUtil;
import com.baitai.common.core.page.TableDataInfo;

/**
 * 用户意见
 * Controller
 *
 * @author xx
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/system/opinion")
public class UserOpinionController extends BaseController {
    @Autowired
    private IUserOpinionService userOpinionService;

    /**
     * 查询用户意见
     * 列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserOpinion userOpinion) {
        startPage();
        List<UserOpinion> list = userOpinionService.selectUserOpinionList(userOpinion);
        return getDataTable(list);
    }
    /**
     * 获取用户意见
     * 详细信息
     */
    @GetMapping(value = "/feedList")
    public AjaxResult getUserOpinion() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        startPage();
        List<UserOpinion> list = userOpinionService.selectUserOpinionByUserId(loginUser.getUserId());
        return AjaxResult.success(getDataTable(list));
    }
    /**
     * 导出用户意见
     * 列表
     */
    @Log(title = "用户意见", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserOpinion userOpinion) {
        List<UserOpinion> list = userOpinionService.selectUserOpinionList(userOpinion);
        ExcelUtil<UserOpinion> util = new ExcelUtil<UserOpinion>(UserOpinion.class);
        util.exportExcel(response, list, "用户意见数据");
    }

    /**
     * 获取用户意见
     * 详细信息
     */
    @GetMapping(value = "/{opinionId}")
    public AjaxResult getInfo(@PathVariable("opinionId") Long opinionId) {
        return success(userOpinionService.selectUserOpinionByOpinionId(opinionId));
    }



    /**
     * 新增用户意见
     */
    @Log(title = "用户意见", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOpinion userOpinion) {
        return toAjax(userOpinionService.insertUserOpinion(userOpinion));
    }

    /**
     * 修改用户意见
     */
    @Log(title = "用户意见", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOpinion userOpinion) {
        return toAjax(userOpinionService.updateUserOpinion(userOpinion));
    }

    /**
     * 删除用户意见
     */
    @Log(title = "用户意见", businessType = BusinessType.DELETE)
    @DeleteMapping("/{opinionIds}")
    public AjaxResult remove(@PathVariable Long[] opinionIds) {
        return toAjax(userOpinionService.deleteUserOpinionByOpinionIds(opinionIds));
    }
}
